home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Commun⁄Network / Telnet 2.5.src.ThinkC / source / event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-16  |  38.7 KB  |  1,510 lines  |  [TEXT/MPS ]

  1. #ifdef lint
  2. static char *SCCSid = "%W%    (NCSA)    %G%";
  3. #endif
  4. /*
  5. *    event.c
  6. *     by Gaige B. Paulsen
  7. ****************************************************************************
  8. *    Part of NCSA Telnet for the Macintosh                                   *
  9. *                                                                          *
  10. *      Uses    :                                                               *
  11. *      TCP/IP kernel for NCSA Telnet                                       *
  12. *      by Tim Krauskopf                                                    *
  13. *       with Macintosh code by Gaige B. Paulsen                                 *
  14. *                                                                          *
  15. *      National Center for Supercomputing Applications                     *
  16. *      152 Computing Applications Building                                 *
  17. *      605 E. Springfield Ave.                                             *
  18. *      Champaign, IL  61820                                                *
  19. *                                                                          *
  20. *                                                                          *
  21. ****************************************************************************
  22. *
  23. *    Main Event loop code for NCSA Telnet for the Macintosh
  24. *
  25. *    Called by:
  26. *        maclook.c
  27. */
  28.  
  29. /*
  30.  *    Files for inclusion.
  31.  */
  32. #include    <stdio.h>
  33. #include    <ctype.h>
  34. #include <string.h>
  35.  
  36. #include    <Controls.h>
  37. #include    <Desk.h>
  38. #include    <Dialogs.h>
  39. #include <DiskInit.h>
  40. #include    <Events.h>
  41. #include    <Fonts.h>
  42. #include    <Menus.h>
  43. #include <Memory.h>
  44. #include <OSEvents.h>
  45. #include    <OSUtils.h>            /* for Juggler */
  46. #include    <Packages.h>
  47. #include    <Quickdraw.h>
  48. #include    <Resources.h>
  49. #include    <Script.h>
  50. #include    <ToolUtils.h>
  51. #include    <Windows.h>
  52.  
  53. #include "configrec.h"
  54. #include "whatami.h"
  55. #include    "VSkeys.h"
  56. #include    "wind.h"
  57. #include    "prefs.h"
  58. #include "user.h"
  59. #include "util.h"
  60. #include "bkgr.h"
  61. #include "maclook.h"
  62. #include "netevent.h"
  63. #include "vsinterf.h"
  64. #include "menu.h"
  65. #include "vrrgmac.h"
  66. #include "tekrgmac.h"
  67. #include "rsmac.h"
  68.  
  69. #ifdef MPW
  70. #include "mpw.h"
  71. #endif
  72.  
  73. /*
  74.  * Event Auxilliary Defines
  75.  */
  76.  
  77. #define KCHR_resource    12000    /* BYU 2.4.12 */
  78.  
  79. #define WaitEvents    10        /* Mouse and Keyboard Dn Events for the Wait4Mouse() */
  80. #define    BScode        51        /* This is the Keycode for Backspace */
  81. #define KPlowest    65        /* This is the last code before the KP */
  82.  
  83. #define switchEvt     1        /* Switching event (suspend/resume )  for app4evt */
  84.  
  85. #define WAITTICKS    3L        /* One (Half) now tenth now 1/20th second for the first try.... */
  86. /*
  87.  *    Font Height and width constants
  88.  */
  89.  
  90. #define Fwidth 6
  91.  
  92.  
  93.  
  94. /*
  95.  *    Window constraints
  96.  */
  97.  
  98.  
  99. #define MAXWINDOWWIDTH  18+Fwidth*80
  100.  
  101. /*
  102.  * Window Defines
  103.  */
  104.  
  105. #define NO_WINDOW    0
  106. #define DEC_WINDOW    1
  107. #define TEK_WINDOW    2
  108.  
  109. /* Macro Defines */
  110. #define MACRO_IP        0xff    /* Send IP number here */
  111. #define MACRO_LINES        0xfe    /* Send # of lines here */
  112.  
  113.  
  114. /* need some menu defines for enableing/disableing the edit menu */
  115.  
  116. #define    NMENUS    8            /*    We have NMENUS menus right now */
  117. #define Edit        2        /*  Edit Menu's Position */
  118. #define    EDundo        1
  119. #define EDcut        3
  120. #define EDcopy        4        /* Edit Menu: Copy */
  121. #define EDpaste        5        /* Edit Menu: Paste */
  122. #define EDclear        6        /* Edit Menu: Clear */
  123. #define EDcopyt        7        /* Edit Menu: Copy Table */
  124. #define EDmacros    9        /* Edit Menu: Macros */
  125. #define EDprefs        10        /* Edit Menu: Preferences */
  126.  
  127. /*
  128.  * ASCII character set defines
  129.  */
  130.  
  131. #define ESC            0x1b    /* the escape character */
  132. #define    BS            0x08    /* the backspace character */
  133. #define DELchar        0x7f    /* BYU LSC - (DEL is defined in MacLook.h) the delete character */
  134. #define CR            0x0d    /* the carriage return character */
  135. #define LF            0x0a    /* the line feed character */
  136. #define    KILLCHAR    0x15    /* the character to kill the local line with */
  137.  
  138. #define Edit        2        /* BYU 2.4.11 - Edit Menu's Position */
  139. #define EDcopy        4        /* BYU 2.4.11 - Edit Menu: Copy */
  140. #define EDcopyt        7        /* BYU 2.4.11 - Edit Menu: Copy Table */
  141.  
  142. #define    Fil            1        /* BYU 2.4.11 - File Menu's Position */
  143. #define FLprint        12        /* BYU 2.4.11 - File Menu: Print Selection */
  144.  
  145. extern void DoTheMenuChecks();
  146. /*
  147.  *    Type declarations for Globals
  148.  */
  149.  
  150. EventRecord
  151.     myEvent;        /* Event Record for main loop */
  152. WindowPeek
  153.     myfrontwindow=0L;    /* window pointer for changing the pointer */
  154. GrafPtr
  155.     whichWindow;    /* window pointer for event loop */
  156. short                /* BYU 2.4.11 */
  157.     cursorBlink,    /* BYU 2.4.11 - 0 = noblink, 1 = blink */
  158.     cursorType,        /* BYU 2.4.11 - 0 = block, 1 = underscore, 2 = vertical line */
  159.     whichKCHR;        /* BYU 2.4.12 */
  160. int
  161.     myfronttype=NO_WINDOW,        /* what kinda window is the front one */
  162.     myfrontvs=0,    /* what is the VS # of the window */
  163.     ctrl=0x100,        /* Key option to use as control */
  164.     suspended=FALSE,/* Are we in the air??? */
  165.     mapTilde=1,        /* Mapping the Tilde, Mapping the Tilde, I'll go a Mapping the Tilde */
  166.     code;            /* code used in mouse operations */
  167. long
  168.     JuggTicks;        /* How many ticks to wait when Juggling */
  169. Handle hKCHR;        /* BYU 2.4.12 - Handle for keyboard mapping stuff */
  170. RgnHandle
  171.     myfrontRgn=0L;    /* Handle to the region of the window to scope for stuff */
  172. Cursor
  173.     *lastCursor=0L;
  174. char
  175.     allthekeys[16];    /* Someplace to put the keymap */
  176.  
  177. #if 0                                    /* BYU 2.4.12 */
  178. int langnum;
  179. #endif                                    /* BYU 2.4.12 */
  180.  
  181. extern MenuHandle myMenus[NMENUS];
  182. extern void AdjustMenus(),ftppi();        /* BYU */
  183.  
  184. unsigned char *macro[10];    /* the wonderful macro package .... */
  185.  
  186. /*
  187.  *    Declarations for constant variables
  188.  */
  189.  
  190. unsigned char kpxlate[2][62] =
  191.   /* table for translating virtual scan codes to internal codes for
  192.     special keys. */
  193.   {
  194.       {        /* virtual key code */
  195.         VSKP,    /* $41 */
  196.         VSRT,    /* $42 (Mac+) */
  197.         VSF4,        /* $43 (ADB) */
  198.         0,        /* $44 */
  199.         VSKC,        /* $45 (ADB std) */
  200.         VSLT,    /* $46 (Mac+) */
  201.         VSF1,    /* $47 */
  202.         VSDN,    /* $48 (Mac+) */
  203.         0,        /* $49 */
  204.         0,        /* $4A */
  205.         VSF3,        /* $4B (ADB) */
  206.         VSKE,    /* $4C */
  207.         VSUP,    /* $4D (Mac+) */
  208.         VSKM,        /* $4E */
  209.         0,        /* $4F */
  210.         0,        /* $50 */
  211.         VSF2,        /* $51 (ADB) */
  212.         VSK0,    /* $52 */
  213.         VSK1,    /* $53 */
  214.         VSK2,    /* $54 */
  215.         VSK3,    /* $55 */
  216.         VSK4,    /* $56 */
  217.         VSK5,    /* $57 */
  218.         VSK6,    /* $58 */
  219.         VSK7,    /* $59 */
  220.         0,        /* $5A */
  221.         VSK8,    /* $5B */
  222.         VSK9,    /* $5C */
  223.         0,        /* $5D */
  224.         0,        /* $5E */
  225.         0,        /* $5F */
  226.         VSF10,    /* $60 */    /* BYU 2.4.12 */
  227.         VSF11,    /* $61 */    /* BYU 2.4.12 */
  228.         VSF12,    /* $62 */    /* BYU 2.4.12 */
  229.         VSF8,    /* $63 */    /* BYU 2.4.12 - was VSF3 */
  230.         VSF13,    /* $64 */    /* BYU 2.4.12 */
  231.         VSF14,    /* $65 */    /* BYU 2.4.12 */
  232.         0,        /* $66 */
  233.         VSF16,    /* $67 */    /* BYU 2.4.12 */
  234.         0,        /* $68 */
  235.         VSF18,    /* $69 */    /* BYU 2.4.12 */
  236.         0,        /* $6A */
  237.         VSF19,    /* $6B */    /* BYU 2.4.12 */
  238.         0,        /* $6C */
  239.         VSF15,    /* $6D */    /* BYU 2.4.12 */
  240.         0,        /* $6E */
  241.         VSF17,    /* $6F */    /* BYU 2.4.12 */
  242.         0,        /* $70 */
  243.         VSF20,    /* $71 */    /* BYU 2.4.12 */
  244.         VSHELP,    /* $72 */    /* BYU 2.4.12 */
  245.         VSHOME,    /* $73 */    /* BYU 2.4.12 */
  246.         VSPGUP,    /* $74 */    /* BYU 2.4.12 */
  247.         VSDEL,    /* $75 (ADB ext) */        /* BYU 2.4.12 - was 0x7f */
  248.         VSF9,    /* $76 */    /* BYU 2.4.12 - was VSF4 */
  249.         VSEND,    /* $77 */    /* BYU 2.4.12 */
  250.         VSF7,    /* $78 */    /* BYU 2.4.12 - was VSF2 */
  251.         VSPGDN,    /* $79 */    /* BYU 2.4.12 */
  252.         VSF6,    /* $7A */    /* BYU 2.4.12 - was VSF1 */
  253.         VSLT,    /* $7B */
  254.         VSRT,    /* $7C */
  255.         VSDN,    /* $7D */
  256.         VSUP    /* $7E */
  257.       },
  258.       {
  259.         VSKP,    /* $41 */
  260.         VSF4,    /* $42 (Mac+) */
  261.         VSF4,        /* $43 (ADB) */
  262.         0,        /* $44 */
  263.         VSKC,        /* $45 (ADB) */
  264.         VSKC,    /* $46 (Mac+) */
  265.         VSF1,    /* $47 */
  266.         VSF2,    /* $48 */
  267.         0,        /* $49 */
  268.         0,        /* $4A */
  269.         VSF3,        /* $4B */
  270.         VSKE,    /* $4C */
  271.         VSF3,    /* $4D */
  272.         VSKM,        /* $4E */
  273.         0,        /* $4F */
  274.         0,        /* $50 */
  275.         VSF2,        /* $51 */
  276.         VSK0,    /* $52 */
  277.         VSK1,    /* $53 */
  278.         VSK2,    /* $54 */
  279.         VSK3,    /* $55 */
  280.         VSK4,    /* $56 */
  281.         VSK5,    /* $57 */
  282.         VSK6,    /* $58 */
  283.         VSK7,    /* $59 */
  284.         0,        /* $5A */
  285.         VSK8,    /* $5B */
  286.         VSK9,    /* $5C */
  287.         0,        /* $5D */
  288.         0,        /* $5E */
  289.         0,        /* $5F */
  290.         VSF10,    /* $60 */    /* BYU 2.4.12 */
  291.         VSF11,    /* $61 */    /* BYU 2.4.12 */
  292.         VSF12,    /* $62 */    /* BYU 2.4.12 */
  293.         VSF8,    /* $63 */    /* BYU 2.4.12 - was VSF3 */
  294.         VSF13,    /* $64 */    /* BYU 2.4.12 */
  295.         VSF14,    /* $65 */    /* BYU 2.4.12 */
  296.         0,        /* $66 */
  297.         VSF16,    /* $67 */    /* BYU 2.4.12 */
  298.         0,        /* $68 */
  299.         VSF18,    /* $69 */    /* BYU 2.4.12 */
  300.         0,        /* $6A */
  301.         VSF19,    /* $6B */    /* BYU 2.4.12 */
  302.         0,        /* $6C */
  303.         VSF15,    /* $6D */    /* BYU 2.4.12 */
  304.         0,        /* $6E */
  305.         VSF17,    /* $6F */    /* BYU 2.4.12 */
  306.         0,        /* $70 */
  307.         VSF20,    /* $71 */    /* BYU 2.4.12 */
  308.         VSHELP,    /* $72 */    /* BYU 2.4.12 */
  309.         VSHOME,    /* $73 */    /* BYU 2.4.12 */
  310.         VSPGUP,    /* $74 */    /* BYU 2.4.12 */
  311.         VSDEL,    /* $75 (ADB ext) */        /* BYU 2.4.12 - was 0x7f */
  312.         VSF9,    /* $76 */    /* BYU 2.4.12 - was VSF4 */
  313.         VSEND,    /* $77 */    /* BYU 2.4.12 */
  314.         VSF7,    /* $78 */    /* BYU 2.4.12 - was VSF2 */
  315.         VSPGDN,    /* $79 */    /* BYU 2.4.12 */
  316.         VSF6,    /* $7A */    /* BYU 2.4.12 - was VSF1 */
  317.         VSLT,    /* $7B */
  318.         VSRT,    /* $7C */
  319.         VSDN,    /* $7D */
  320.         VSUP    /* $7E */
  321.       }
  322.   };
  323.  
  324. extern SysEnvRec theWorld;        /* BYU 2.4.12 - System Environment record */
  325.  
  326. extern Rect
  327.     dragRect;        /* Where it is legal to drag ourselves */
  328.  
  329. extern long
  330.     SysScriptKeys,
  331.     SysScriptIcon;
  332.  
  333. extern WindRec
  334.     console,
  335.     ftplog,
  336.     *screens;
  337.  
  338. extern short slip_connection;    /* BYU 2.4.16 */
  339.  
  340. extern int
  341.     numwindows,                /* The number of windows now from Maclook */
  342.     ginon,
  343.     xferon,
  344.     whichMenus,
  345.     ScriptManager,
  346.     Juggling,        /* Are we Juggling?????    */
  347.     scrn;
  348. extern Cursor
  349.     *graphcurs,        /* Cursor when in graphic window */
  350.     *gincurs,        /* Cursor when in graphics input mode */
  351.     *xfercurs,        /* Cursor when in transfer mode */
  352.     *normcurs,        /* Cursor for non-transfer normal mode */
  353.     *textcurs,        /* Cursor for text mode */
  354.     *poscurs,        /* Cursor for positioning mode */
  355.     *watchcurs;        /* Cursor for time-taking operations */
  356.  
  357. void optionKeys        /* BYU 2.4.18 - put this procedure back in */
  358.   (
  359.     void
  360.   )
  361. {
  362.     int err;
  363.  
  364.     SysScriptKeys = GetScript(smRoman, smScriptKeys);
  365.     SysScriptIcon = GetScript(smRoman, smScriptIcon);
  366.  
  367.  
  368.     if (!(Prefs.optKeys && ScriptManager))
  369.         return;
  370.  
  371.     err= SetScript( smRoman, smScriptKeys, 12000);
  372.     if (err)
  373.         return;
  374.     err= SetScript( smRoman, smScriptIcon, 12000);
  375.     if (err)
  376.         return;
  377.     KeyScript(smRoman);
  378.  
  379.     putln("OPTIONAL option key processing installed");
  380. }
  381.  
  382. void optionKeysOff        /* BYU 2.4.18 - put this procedure back in */
  383.   (
  384.     void
  385.   )
  386. {
  387.  
  388.     int err;
  389.  
  390.     if (!ScriptManager)
  391.         return;
  392.  
  393.     if  (!Prefs.optKeys) return;
  394.     
  395.     
  396.     err= SetScript( smRoman, smScriptKeys, SysScriptKeys);
  397.     if (err)
  398.         return;
  399.     err= SetScript( smRoman, smScriptIcon, SysScriptIcon);
  400.     if (err)
  401.         return;
  402. /*    KeyScript(smRoman);   */
  403. }
  404.  
  405. void setmacro                /* Set macro number <n> to the value of s */
  406.   (
  407.     int n,
  408.     unsigned char *s
  409.   )
  410. {
  411.     unsigned char *p;
  412.     int num=0, pos=0, escape=0;
  413.  
  414.     if (n<0  || n>9)
  415.         return;
  416.  
  417.     p=macro[n];
  418.  
  419.     while ( *s) {
  420.         if (escape) {
  421.             escape=0;
  422.             switch (*s) {
  423.                 case 'i':
  424.                     if ( pos >0) {
  425.                         *p++=num;
  426.                         *p++=*s;
  427.                         pos=0;
  428.                         }
  429.                     *p++=MACRO_IP;
  430.                     break;
  431.                 case '#':
  432.                     if ( pos >0) {
  433.                         *p++=num;
  434.                         *p++=*s;
  435.                         pos=0;
  436.                         }
  437.                     *p++=MACRO_LINES;
  438.                     break;
  439.                 case 'n':
  440.                     if ( pos >0) {
  441.                         *p++=num;
  442.                         *p++=*s;
  443.                         pos=0;
  444.                         }
  445.                     *p++='\012';
  446.                     break;
  447.                 case 'r':
  448.                     if ( pos >0) {
  449.                         *p++=num;
  450.                         *p++=*s;
  451.                         pos=0;
  452.                         }
  453.                     *p++='\015';
  454.                     break;
  455.                 case 't':
  456.                     if ( pos >0) {
  457.                         *p++=num;
  458.                         *p++=*s;
  459.                         pos=0;
  460.                         }
  461.                     *p++='\t';
  462.                     break;
  463.                 case '"':
  464.                     if ( pos >0) {
  465.                         *p++=num;
  466.                         *p++=*s;
  467.                         pos=0;
  468.                         }
  469.                     *p++='\"';
  470.                     break;
  471.  
  472.                         
  473.                 case '\\':
  474.                     if ( pos >0) {
  475.                         *p++=num;
  476.                         escape=1;
  477.                         pos=0;
  478.                         num=0;
  479.                         }
  480.                     else
  481.                         *p++='\\';
  482.                     break;
  483.                 default:
  484.                     if (*s <='9' && *s >='0' && pos <3) {
  485.                         num= num*8+( *s -'0');
  486.                         pos++;
  487.                         escape=1;
  488.                         }
  489.                     else {
  490.                         if (pos ==0 && num==0) {
  491.                             *p++='\\';
  492.                             *p++=*s;
  493.                             }
  494.                         else {
  495.                             *p++=num;
  496.                             pos= 0;
  497.                             s--;            /* back up the buffer. */
  498.                             }
  499.                         }
  500.                     break;
  501.                 }
  502.             }
  503.         else {
  504.             if (*s=='\\') {
  505.                 num=0;
  506.                 pos=0;
  507.                 escape=1;
  508.                 }
  509.             else
  510.                 *p++=*s;
  511.             }
  512.         s++;
  513.         }
  514.  
  515.     if (pos >0) *p++=num;
  516.     *p=0;
  517. } /* setmacro */
  518.  
  519. void initmacros
  520.   (
  521.     void
  522.   )
  523. {
  524.     int i;
  525.  
  526.     for (i=0; i<10 ; i++) {
  527.         macro[i] = (unsigned char *) NewPtr(256);        /* BYU LSC */
  528.         if (macro[i]== NULL) {
  529.             OtherError((char *) "\pNo space for macro storage",(char *) "\pFatal error");    /* BYU LSC */
  530.             quit();
  531.             }
  532.         setmacro( i, (unsigned char *) "");        /* BYU LSC */
  533.         }
  534. }
  535.  
  536. void initKeyBoardMapping(void) {                            /* BYU 2.4.13 */
  537.     long myscript;                                            /* BYU 2.4.13 */
  538.                                                             /* BYU 2.4.13 */
  539. /* First try to use the default System 7 keyborad mapping.    /* BYU 2.4.13 */
  540. /* When that fails use the application's KCHR resource if     /* BYU 2.4.13 */
  541. /* it's the only one in town.                                /* BYU 2.4.13 */
  542.                                                             /* BYU 2.4.13 */
  543. /* Release the previously selected resource.                  /* BYU 2.4.13 */
  544.     if (hKCHR)                                                /* BYU 2.4.13 */
  545.         ReleaseResource(hKCHR);                                /* BYU 2.4.13 */
  546.                                                             /* BYU 2.4.13 */
  547.     if (Prefs.systemKCHR) {                                    /* BYU 2.4.18 */
  548.         myscript = GetEnvirons(smKeyScript);                /* BYU 2.4.18 */
  549.         if (myscript && ScriptManager) {                    /* BYU 2.4.18 */
  550.             whichKCHR = GetScript(myscript,smScriptKeys);    /* BYU 2.4.18 */
  551.             if (whichKCHR)                                    /* BYU 2.4.18 */
  552.                 hKCHR = GetResource('KCHR',whichKCHR);        /* BYU 2.4.18 */
  553.         }                                                    /* BYU 2.4.18 */
  554.         if (!hKCHR) {                                        /* BYU 2.4.18 */
  555.             whichKCHR = KCHR_resource;                        /* BYU 2.4.18 */
  556.             hKCHR = GetResource('KCHR', whichKCHR);            /* BYU 2.4.18 */
  557.         }                                                    /* BYU 2.4.18 */
  558.     } else {                                                /* BYU 2.4.18 */
  559.                                                             /* BYU 2.4.18 */
  560. /* Use the application KCHR resource */                        /* BYU 2.4.18 */
  561.         whichKCHR = KCHR_resource;                            /* BYU 2.4.13 */
  562.         hKCHR = GetResource('KCHR', whichKCHR);                /* BYU 2.4.13 */
  563.                                                             /* BYU 2.4.13 */
  564. /* If mapping "option" to "control" is not active, or the     /* BYU 2.4.13 */
  565. /* application  KCHR resource has been removed, use the     /* BYU 2.4.13 */
  566. /* system KCHR resource for mapping keys.                     /* BYU 2.4.13 */
  567.         if (!hKCHR) {                                            /* BYU 2.4.13 */
  568.             myscript = GetEnvirons(smKeyScript);                /* BYU 2.4.13 */
  569.             if (myscript && ScriptManager) {                    /* BYU 2.4.13 */
  570.                 whichKCHR = GetScript(myscript,smScriptKeys);    /* BYU 2.4.13 */
  571.                 if (whichKCHR)                                    /* BYU 2.4.13 */
  572.                     hKCHR = GetResource('KCHR',whichKCHR);        /* BYU 2.4.13 */
  573.             }                                                    /* BYU 2.4.13 */
  574.         }                                                    /* BYU 2.4.13 */
  575.     }                                                        /* BYU 2.4.13 */
  576.                                                             /* BYU 2.4.13 */
  577.     if (!hKCHR)                                                /* BYU 2.4.13 */
  578.         whichKCHR = 0;                                        /* BYU 2.4.13 */
  579. }
  580.  
  581. void initEvents
  582.   (
  583.     void
  584.   )
  585. {
  586.     long myscript;                            /* BYU 2.4.12 */
  587.  
  588.     initmacros();
  589.  
  590.     if (theWorld.systemVersion < 0x0700)    /* BYU 2.4.18 */
  591.         optionKeys();                        /* BYU 2.4.18 */
  592.  
  593.     FlushEvents(everyEvent - diskEvt,0);    /* Don't Let 'em get off without seeing it. */
  594.  
  595.     JuggTicks=WAITTICKS;
  596.  
  597. #if 0                        /* BYU LSC - initialized in "environ.c" */
  598.     Juggling = 0;
  599. #endif                        /* BYU LSC */
  600.  
  601.     mapTilde = Prefs.mapTilde;
  602.     if (GetTrapAddress( 0x60) != GetTrapAddress( 0x9f) ) {
  603.         Juggling = 1;
  604.         putln("Juggling!");        /* BYU */
  605.         WaitNextEvent(everyEvent, &myEvent, JuggTicks, 0L);
  606.         WaitNextEvent(everyEvent, &myEvent, JuggTicks, 0L);
  607.         }
  608.  
  609.     hKCHR = 0;                                    /* BYU 2.4.13 */
  610.     initKeyBoardMapping();                        /* BYU 2.4.12 */
  611.  
  612. #if 0                                            /* BYU 2.4.12 */
  613.     else Juggling =0;                            /* BYU LSC - Currently only check for Juggler */
  614.     putln("Done with initEvents()");
  615. #endif                                            /* BYU 2.4.12 */
  616. }
  617.  
  618. void JTime
  619.   (
  620.     int i
  621.   )
  622.   {
  623.     if (i >= 0)
  624.         JuggTicks = i;
  625.   }
  626.  
  627. int updateCursor
  628.   (
  629.     int force
  630.   )
  631. {
  632.     static long lastPoint;
  633.     static int optwasdown;
  634.     int optDown;
  635.     long myPoint;
  636.  
  637.     if (myfrontwindow) {                    /* BYU 2.4.11 */
  638.         SetPort((GrafPtr) myfrontwindow);    /* BYU 2.4.11 */
  639.     } else {                                /* BYU 2.4.11 */
  640.         SetCursor(normcurs);                /* BYU 2.4.11 */
  641.         return(0);                            /* BYU 2.4.11 */
  642.     }
  643.  
  644.     GetMouse((Point *) &myPoint);
  645.  
  646.     GetKeys((KeyMap *) &allthekeys);        /* BYU 2.4.12 */
  647.     optDown = allthekeys[7] &4;
  648.  
  649.     if ( (!force) && (myPoint == lastPoint) && (optDown ==optwasdown))
  650.         return(0);
  651.  
  652.     if (force)
  653.         lastCursor=0L;
  654.     if (ginon) {
  655.         if (lastCursor!= gincurs) {
  656.             SetCursor( gincurs);
  657.             lastCursor = gincurs;
  658.             }
  659.         return(1);
  660.         }
  661.  
  662.     if (xferon && !optDown) {
  663.         if  (lastCursor!= xfercurs) {
  664.             SetCursor( xfercurs);
  665.             lastCursor = xfercurs;
  666.             }
  667.         return(1);
  668.         }
  669.  
  670.     switch (myfronttype) {
  671.         case DEC_WINDOW:
  672.             if (RSmouseintext( myfrontvs, myPoint)) {
  673.                 if (optDown) {                /* Option key is down */
  674.                     if (lastCursor !=poscurs) {
  675.                         lastCursor  =poscurs;
  676.                         SetCursor(poscurs);
  677.                         }
  678.                 } else {
  679.                     if (lastCursor !=textcurs) {
  680.                         lastCursor  =textcurs;
  681.                         SetCursor(textcurs);
  682.                         }
  683.                     }
  684.             } else {
  685.                 if (lastCursor !=normcurs) {
  686.                     lastCursor  =normcurs;
  687.                     SetCursor(normcurs);
  688.                     }
  689.             }
  690.             break;
  691.         case TEK_WINDOW:
  692.             LocalToGlobal((Point *) &myPoint);
  693.             if (PtInRgn( *(Point *) &myPoint, myfrontwindow->contRgn)) {        /* BYU LSC */
  694.                 if (lastCursor !=graphcurs) {
  695.                     lastCursor  =graphcurs;
  696.                     SetCursor(graphcurs);
  697.                     }
  698.             } else {
  699.                 if (lastCursor !=normcurs) {
  700.                     lastCursor  =normcurs;
  701.                     SetCursor(normcurs);
  702.                     }
  703.             }
  704.             break;
  705.         case NO_WINDOW:
  706.         default:
  707.             if (force) {
  708.                 SetCursor( normcurs);
  709.                 lastCursor= normcurs;
  710.                 }
  711.         }
  712.     lastPoint=myPoint;
  713.     optwasdown=optDown;
  714.     return(0);
  715. }
  716.  
  717. void NoWindow
  718.   (
  719.     void
  720.   )
  721. {
  722.         myfrontwindow=0L;
  723.         myfronttype=NO_WINDOW;
  724.         myfrontRgn=0L;
  725.         updateCursor(1);
  726. }
  727.  
  728. int sendmacro                /* send macro number n */
  729.   (
  730.     int n
  731.   )
  732. {
  733.     unsigned char temp[300], *mp, *tp;
  734.     extern unsigned char myipnum[4];
  735.  
  736.     if (n<0 || n>9) return(-1);
  737.  
  738.     tp = temp;
  739.     mp = macro[n];
  740.     while ( *mp) {
  741.         if ( *mp==MACRO_IP) {
  742.             sprintf((char *) tp,"%d.%d.%d.%d", myipnum[0], myipnum[1], myipnum[2], myipnum[3]);        /* BYU LSC */
  743.             tp+=strlen((char *) tp);    /* BYU LSC */
  744.             mp++;
  745.             }
  746.         else if ( *mp==MACRO_LINES) {
  747.             sprintf((char *) tp,"%d", VSgetlines( screens[scrn].vs));    /* BYU LSC */
  748.             tp+=strlen((char *) tp);    /* BYU LSC */
  749.             mp++;
  750.             }
  751.         else if (screens[scrn].ftpstate) {                                /* BYU 2.4.16 */
  752.             if (*mp == CR) {                                            /* BYU 2.4.16 */
  753.                 parse( &screens[scrn],(unsigned char *) "\015\012",2);    /* BYU 2.4.16 */
  754.                 screens[scrn].kbbuf[ screens[scrn].kblen++ ] = 0;        /* BYU 2.4.16 */
  755.                 ftppi(screens[scrn].kbbuf);                                /* BYU 2.4.16 - ftp client */
  756.                 screens[scrn].kblen=0;                                    /* BYU 2.4.16 */
  757.                 mp++;                                                    /* BYU 2.4.16 */
  758.             } else {                                                    /* BYU 2.4.16 */
  759.                 screens[scrn].kbbuf[ screens[scrn].kblen++ ] = *mp;        /* BYU 2.4.16 */
  760.                 parse( &screens[ scrn], mp++, 1);                        /* BYU 2.4.16 */
  761.             }                                                            /* BYU 2.4.16 */
  762.         } else *tp++=*mp++;                                                /* BYU 2.4.16 */
  763.     }                                                                    /* BYU 2.4.16 */
  764.     *tp=0;                        /* Gotta have a nul! */
  765.     tp= temp;
  766.  
  767.     if (!screens[scrn].ftpstate &&                                         /* BYU 2.4.16 */
  768.         (screens[scrn].connectionType == 0 || slip_connection)) {        /* BYU 2.4.16 */
  769.  
  770.         netpush( screens[scrn].port);                                    /* BYU 2.4.16 */
  771.  
  772.         if (screens[scrn].lmflag)     /* need to flush buffer */            /* BYU 2.4.16 */
  773.             {                                                            /* BYU 2.4.16 */
  774.             netwrite(screens[scrn].port,screens[scrn].kbbuf,screens[scrn].kblen);    /* BYU 2.4.16 */
  775.             screens[scrn].kblen=0;                                        /* BYU 2.4.16 */
  776.             }                                                            /* BYU 2.4.16 */
  777.     }                                                                    /* BYU 2.4.16 */
  778.  
  779.     if (!screens[scrn].ftpstate) {                                        /* BYU 2.4.16 */
  780.         netwrite(screens[scrn].port, tp, strlen((char *) tp) );            /* BYU LSC */
  781.     
  782.         if (screens[scrn].echo)
  783.             parse( &screens[scrn],tp, strlen((char *) tp) );            /* BYU LSC */
  784.     }                                                                    /* BYU 2.4.16 */
  785.  
  786.     return(0);
  787. }
  788.  
  789. long InterpretMessage(EventRecord *event) {                        /* BYU 2.4.12 */
  790.   long message;                                                    /* BYU 2.4.12 */
  791.   long state=0;                                                    /* BYU 2.4.12 */
  792.   short keycode;                                                /* BYU 2.4.12 */
  793.                                                                 /* BYU 2.4.12 */
  794. /* Default to the application KCHR resource.                    /* BYU 2.4.12 */
  795. /* If it is missing then try the current system resource.         /* BYU 2.4.12 */
  796.                                                                 /* BYU 2.4.12 */
  797.     if (whichKCHR)                                                /* BYU 2.4.12 */
  798.         hKCHR = GetResource('KCHR', whichKCHR);                    /* BYU 2.4.12 */
  799.     else                                                        /* BYU 2.4.12 */
  800.         return(event->message);                                    /* BYU 2.4.12 */
  801.                                                                 /* BYU 2.4.12 */
  802.     if (!hKCHR) {                                                /* BYU 2.4.12 */
  803.         message = event->message;                                /* BYU 2.4.12 */
  804.     } else {                                                    /* BYU 2.4.12 */
  805.         keycode = ((event->message>>8) & 0xff) |                 /* BYU 2.4.12 */
  806.             (event->modifiers & 0xff00);                        /* BYU 2.4.12 */
  807.         message = KeyTrans(*hKCHR, keycode, &state);            /* BYU 2.4.12 */
  808.         message = (message & 0xff) | (event->message & 0xff00);    /* BYU 2.4.12 */
  809.     }                                                            /* BYU 2.4.12 */
  810.                                                                 /* BYU 2.4.12 */
  811.   return(message);                                                /* BYU 2.4.12 */
  812. }                                                                /* BYU 2.4.12 */
  813.  
  814. void doKeys
  815.   (
  816.     void
  817.   )
  818. {
  819.     int ascii,code;
  820.     unsigned char sendch;
  821.     long menuEquiv;
  822.     short enterkey =0;
  823.         
  824.     ObscureCursor();
  825.  
  826. /* If the option key is not mapped to the control key            /* BYU 2.4 12 */
  827. /*   then map it per the KCHR resource                             /* BYU 2.4.12 */
  828. /*    if ((!Prefs.optKeys) && (myEvent.modifiers & optionKey))    /* BYU 2.4.12 */
  829. /*        myEvent.message = InterpretMessage(&myEvent);            /* BYU 2.4.12 */
  830.  
  831. /* Map all keys by the appropriate Script/KCHR resource.        /* BYU 2.4.12 */
  832.     myEvent.message = InterpretMessage(&myEvent);                /* BYU 2.4.13 */
  833.  
  834.     ascii = myEvent.message & charCodeMask;
  835.     code = (myEvent.message & keyCodeMask) >> 8;
  836.     if ((myEvent.modifiers & cmdKey) && (menuEquiv = MenuKey(ascii))) {
  837.         docommand(menuEquiv,myEvent.modifiers);
  838.         return;
  839.     }
  840.  
  841.     if ((myEvent.modifiers & ( optionKey | controlKey)) && (ascii==32))
  842.                 ascii=0;            /* ASCII nul value for command-spacebar */
  843.  
  844.     if (myEvent.modifiers & cmdKey)  {
  845.         if (ascii==';' ) {            /* debugging information on cmd-; */
  846.             int i;
  847.             char temp[50];
  848.             for (i=0; i<numwindows; i++) {
  849.                 sprintf(temp, "[%d]  %d (%d) %s", i,screens[i].port, screens[i].active, screens[i].machine);
  850.                 putln(temp);
  851.                 }
  852.             }
  853.         }         
  854.  
  855.     if (screens[scrn].corpse)
  856.         return;
  857.  
  858.     if (myEvent.modifiers & cmdKey)  {
  859.         if (ascii >='0' && ascii <='9' )  {            /* handle key macros */
  860.             sendmacro( ascii-'0');
  861.             return;
  862.             }
  863.         }
  864.  
  865.     if (numwindows<1 || ((myEvent.modifiers & cmdKey ) && whichMenus))
  866.         return;
  867.  
  868. #if 0                                                /* BYU 2.4.12 */
  869.     if (code == 0x77) {                                /* Flush on <end> */
  870.         FlushNetwork(scrn);
  871.         return;
  872.         }
  873. #endif                                                /* BYU 2.4.12 */
  874.  
  875.     if (!screens[scrn].ftpstate && (code >= KPlowest)) {        /* BYU - Handle Keypad */
  876.         int shifted;
  877.         shifted = (myEvent.modifiers & shiftKey) != 0;
  878.         if (theWorld.keyBoardType == envStandADBKbd)    /* BYU 2.4.12 */
  879.     
  880.             if (code == 0x45)
  881.                 code = 0x4e;
  882.             else if (code == 0x4e)
  883.                 code = 0x45;                
  884.         ascii = kpxlate[shifted][code - KPlowest];
  885.         VSkbsend(screens[scrn].vs, (unsigned char) ascii, screens[scrn].echo);
  886.         return;
  887.       }
  888.  
  889.     /* BSD-like mapping.... if we don't want this, set chars to something >128 and it wont work */
  890.     if (ascii == screens[scrn].TELstop)  {
  891.         screens[scrn].enabled = 0;
  892.         return;
  893.         }
  894.  
  895.     if (ascii == screens[scrn].TELgo) {
  896.         screens[scrn].enabled = 1;
  897.         return;
  898.         }
  899.  
  900.  
  901.         
  902.     if (ascii == screens[scrn].TELip)  {
  903.         netpush(screens[scrn].port);
  904.         netwrite(screens[scrn].port, "\377\364",2);
  905.         screens[ scrn].timing = 1;                            /* set emulate to TMwait */
  906.         netwrite(screens[scrn].port, "\377\375\006",3);        /* send TM */
  907.         if (screens[scrn].lmflag) 
  908.             screens[scrn].kblen=0;
  909.         return;
  910.         }
  911.  
  912.     ascii &= 0x7f;        /* Don't allow those bluming option chars */
  913.     
  914.     if (ascii == '`' && mapTilde) ascii = ESC;                    /* Map '`' to ESC */
  915.  
  916.     if ((screens[scrn].bsdel) && (code==BScode)) ascii=DELchar;
  917.  
  918.     if (myEvent.modifiers & (optionKey | cmdKey)) {    /* Map control chars */
  919.         if (ascii == ESC)                            /* the '`' remains the same */
  920.             ascii = '`';
  921.         else
  922.             if (code == BScode) {                    /* Swap only the true bksp */
  923.                 if (screens[scrn].bsdel) ascii=BS;
  924.                     else ascii=DELchar;
  925.                 }
  926.         else {
  927.             if (Prefs.optKeys || !Prefs.cmdKeys)    /* Option or command remapped to control */
  928.                 ascii &= 0x1f;                        /* All other chars are ctrl */
  929.             }
  930.         }
  931.  
  932.  
  933.     if (screens[scrn].ftpstate)                            /* BYU - ftpclient */
  934.         {                                                /* BYU */
  935.         if (ascii>31 && ascii <127 && code<KPlowest)    /* BYU - add these chars to buffer */
  936.             {                                            /* BYU */
  937.             if (screens[scrn].kblen < (MAXKB -1))         /* BYU - Add to buffer if not full */
  938.                 {                                        /* BYU */
  939.                 screens[scrn].kbbuf[ screens[scrn].kblen++ ] = ascii;    /* BYU */
  940.                 sendch=ascii;                            /* BYU */
  941.                 parse( &screens[ scrn], &sendch, 1);    /* BYU */
  942.                 }                                        /* BYU */
  943.             else                                         /* BYU */
  944.                 SysBeep(4);                                /* BYU - buffer full */
  945.             }                                            /* BYU */
  946.         else                                            /* BYU - not printable char */
  947.             {                                            /* BYU */
  948.             if ( code == BScode )                         /* BYU */
  949.                 {                                        /* BYU */
  950.                 if (screens[scrn].kblen>0)                 /* BYU */
  951.                     {                                    /* BYU */
  952.                     screens[scrn].kblen--;                    /* BYU */
  953.                     parse( &screens[scrn],(unsigned char *) "\010 \010",3);    /* BYU */
  954.                     }                                        /* BYU */
  955.                 }                                        /* BYU */
  956.             else if (ascii == CR)                        /* BYU */
  957.                 {                                        /* BYU */
  958.                 parse( &screens[scrn],(unsigned char *) "\015\012",2);        /* BYU */
  959.                 screens[scrn].kbbuf[ screens[scrn].kblen++ ] = 0;    /* BYU */
  960.                 ftppi(screens[scrn].kbbuf);                            /* BYU - ftp client */
  961.                 screens[scrn].kblen=0;                    /* BYU */
  962.                 }                                        /* BYU */
  963.             else if (ascii == KILLCHAR)                 /* BYU */
  964.                 {                                        /* BYU */
  965.                 while (screens[scrn].kblen >0)             /* BYU */
  966.                     {                                        /* BYU */
  967.                     parse( &screens[scrn],(unsigned char *) "\010 \010",3);    /* BYU */
  968.                     screens[scrn].kblen--;                    /* BYU */
  969.                     }                                    /* BYU */
  970.                 }
  971.             }
  972.         return;                                            /* BYU */
  973.         }
  974.  
  975.     else if (screens[scrn].lmflag)    /* I'm in line-Mode... aren't you?? */
  976.         {    
  977.         if (screens[scrn].echo && ! screens[scrn].halfdup)    /* Handle local ECHOs */
  978.  
  979.             if (ascii>31 && ascii <127 && code<KPlowest)    /* add these chars to buffer */
  980.                 {
  981.                 if (screens[scrn].kblen < (MAXKB -1))     /* Add to buffer if not full */
  982.                     screens[scrn].kbbuf[ screens[scrn].kblen++ ] = ascii;
  983.                 else 
  984.                     {                
  985.                     netwrite( screens[scrn].port, screens[scrn].kbbuf, screens[scrn].kblen);    /* if full send buffer */
  986.                     screens[scrn].kbbuf[0]=ascii;
  987.                     screens[scrn].kblen=1;
  988.                     }
  989.  
  990.                 sendch=ascii;
  991.                 parse( &screens[ scrn], &sendch, 1);
  992.                 if (!screens[scrn].halfdup)    
  993.                     return;                                /* OK, were set...*/
  994.     
  995.                 }
  996.              else                    /* not printable char */
  997.                 {
  998.                 if ( code == BScode ) 
  999.                     {
  1000.                     if (screens[scrn].kblen>0) 
  1001.                         {
  1002.                         screens[scrn].kblen--;
  1003.                         parse( &screens[scrn],(unsigned char *) "\010 \010",3);    /* BYU LSC */
  1004.                         }
  1005.                     return;
  1006.                     }
  1007.                 else if (ascii == CR) 
  1008.                     {
  1009.                     char tt[50];
  1010.                     
  1011.                     netwrite( screens[scrn].port, screens[scrn].kbbuf, screens[scrn].kblen);
  1012.                     sprintf(tt,"length %i ",(int)screens[scrn].kblen);
  1013.                     putln(tt);
  1014.                     screens[scrn].kblen=0;
  1015.                     }
  1016.     
  1017.                 else if (ascii == KILLCHAR) 
  1018.                     {
  1019.                     while (screens[scrn].kblen >0) 
  1020.                         {
  1021.                         parse( &screens[scrn],(unsigned char *) "\010 \010",3);    /* BYU LSC */
  1022.                         screens[scrn].kblen--;
  1023.                         }
  1024.                     return;
  1025.                     }
  1026.  
  1027.                 else if (code <KPlowest) 
  1028.                     {
  1029.                     netwrite( screens[scrn].port, screens[scrn].kbbuf, screens[scrn].kblen);    /* if full send buffer */
  1030.                     screens[scrn].kblen=0;
  1031.                     
  1032.                     if (ascii !=CR) 
  1033.                         {
  1034.                         char crapp[5];
  1035.                         
  1036.                         if (ascii == 26)    /* job control */
  1037.                             {
  1038.                             sprintf(crapp,"%c%c",255,237);
  1039.                             netwrite(screens[scrn].port,crapp,2);
  1040.                             parse( &screens[scrn],(unsigned char *) "^",1);    /* BYU LSC */
  1041.                             parse( &screens[scrn], &sendch, 1);
  1042.                             return;
  1043.  
  1044.                             }
  1045.                         sendch='@'+ascii;
  1046.                         parse( &screens[scrn],(unsigned char *) "^",1);        /* BYU LSC */
  1047.                         parse( &screens[scrn], &sendch, 1);
  1048.                         }
  1049.                     }
  1050.                 }
  1051.             }
  1052.             
  1053.     else        /* BYU = was: if (!screens[scrn].lmflag ) */
  1054.         {
  1055.         if (screens[scrn].echo && ! screens[scrn].halfdup)        /* Handle local ECHOs */
  1056.             if (ascii>31 && ascii <127 && code<KPlowest)    
  1057.                 {
  1058.                 if (screens[scrn].kblen < (MAXKB -1))     /* Add to buffer if not full */
  1059.                     screens[scrn].kbbuf[ screens[scrn].kblen++ ] = ascii;
  1060.                 else 
  1061.                     {                    
  1062.                     netwrite( screens[scrn].port, screens[scrn].kbbuf,
  1063.                     screens[scrn].kblen);    /* if full send buffer */    
  1064.                     screens[scrn].kbbuf[ 0 ]=ascii;
  1065.                     screens[scrn].kblen=1;
  1066.                     }
  1067.  
  1068.                 sendch=ascii;
  1069.                 parse( &screens[ scrn], &sendch, 1);
  1070.                 if (!screens[scrn].halfdup)    
  1071.                     return;                                /* OK, were set...*/
  1072.                 }
  1073.             else 
  1074.                 {
  1075.                 if ( code == BScode ) 
  1076.                     {
  1077.                     if (screens[scrn].kblen>0) 
  1078.                         {
  1079.                         screens[scrn].kblen--;
  1080.                         parse( &screens[scrn],(unsigned char *) "\010 \010",3);    /* BYU LSC */
  1081.                         }
  1082.                     return;
  1083.                     }
  1084.                 else if (ascii == KILLCHAR) 
  1085.                     {
  1086.                     while (screens[scrn].kblen >0) 
  1087.                         {
  1088.                         parse( &screens[scrn],(unsigned char *) "\010 \010",3);    /* BYU LSC */
  1089.                         screens[scrn].kblen--;
  1090.                         }
  1091.                     return;
  1092.                     }
  1093.         
  1094.                 else if (code <KPlowest) 
  1095.                     {
  1096.                     netwrite( screens[scrn].port, screens[scrn].kbbuf,
  1097.                     screens[scrn].kblen);    /* if full send buffer */
  1098.                     screens[scrn].kblen=0;
  1099.                     if (ascii !=CR) 
  1100.                         {
  1101.                         sendch='@'+ascii;
  1102.                         parse( &screens[scrn],(unsigned char *) "^",1);    /* BYU LSC */
  1103.                         parse( &screens[scrn], &sendch, 1);
  1104.                         }
  1105.                     }
  1106.                 }
  1107.             }
  1108.             
  1109.  
  1110.     if (ascii == '\015')                         /* BYU 2.4.18 - changed \n to \015 */
  1111.         {        /* Map CR->CRLF */
  1112.         netpush( screens[scrn].port);
  1113.         if ((!screens[scrn].lmflag) || (!screens[scrn].crmap)) netwrite(screens[scrn].port,"\015",1);
  1114.         ascii=screens[scrn].crmap;
  1115.         if (screens[scrn].echo) parse( &screens[scrn],(unsigned char *) "\012\015",2);    /* BYU LSC */
  1116.         if (screens[scrn].connectionType && !slip_connection)                /* BYU 2.4.18 */
  1117.             return;                                                            /* BYU 2.4.18 */
  1118.         }
  1119.  
  1120. #ifdef OLD_STUFF
  1121.     if (ascii == '\r')
  1122.         {
  1123.         netwrite(screens[scrn].port,"\r",1);
  1124.         netpush(screens[scrn].port);
  1125.         ascii = screens[scrn].crmap;
  1126.         if (screens[scrn].echo) parse (&screens[scrn],"\r\012",2);
  1127.         }
  1128. #endif
  1129.  
  1130.     if (screens[scrn].echo && screens[scrn].halfdup) 
  1131.         {
  1132.         sendch=ascii;
  1133.         parse( &screens[scrn], &sendch, 1);
  1134.         }
  1135.  
  1136.     sendch= ascii;
  1137.     netwrite(screens[scrn].port,&sendch,1);
  1138.     netpush(screens[scrn].port);                    /* DAMN PYRAMIDS! */
  1139.  
  1140. }
  1141.  
  1142. void DoEvents
  1143.   (
  1144.     void
  1145.   )
  1146. {
  1147.     Boolean gotOne;            /* Did we get an event */
  1148.     int vs;                    /* BYU 2.4.11 */
  1149.  
  1150.     if (Juggling)
  1151.         gotOne = WaitNextEvent(everyEvent, &myEvent, JuggTicks, 0L);
  1152.     else
  1153.       {
  1154.         SystemTask();                        /* love those desk acc. */
  1155.         gotOne = GetNextEvent(everyEvent, &myEvent);
  1156.       }
  1157.  
  1158.     if (gotOne) {
  1159.  
  1160. /* BYU 2.4.11 - Turn the cursor off when the human makes the slightest move. */
  1161.         if (cursorBlink) {                                /* BYU 2.4.11 */
  1162.             whichWindow = FrontWindow();                /* BYU 2.4.11 */
  1163.             if ( (vs=RSfindvwind(whichWindow)) >= 0)    /* BYU 2.4.11 */
  1164.                 if (vs == screens[scrn].vs)                /* BYU 2.4.11 */
  1165.                     if (!(myEvent.modifiers & cmdKey) &&    /* BYU 2.4.18 */
  1166.                         ((myEvent.what == keyDown) ||         /* BYU 2.4.18 */
  1167.                          (myEvent.what == autoKey)))        /* BYU 2.4.18 */
  1168.                         RScursblinkon(vs);                /* BYU 2.4.18 */
  1169.                     else                                /* BYU 2.4.18 */
  1170.                         RScursblinkoff(vs);                /* BYU 2.4.18 */
  1171.         }                                                /* BYU 2.4.11 */
  1172.  
  1173.         switch(myEvent.what) {
  1174.         case mouseDown:
  1175.             code = FindWindow(myEvent.where, &whichWindow);        /* BYU LSC */
  1176.             switch (code) {
  1177.             case inMenuBar:
  1178.                 docommand(MenuSelect(myEvent.where),myEvent.modifiers);    /* BYU LSC */
  1179.                 break;
  1180.             case inSysWindow:
  1181.                 SystemClick(&myEvent, whichWindow);
  1182.                 break;
  1183.             case inGoAway:
  1184.                 if (TrackGoAway( whichWindow, myEvent.where)) {    /* BYU LSC */
  1185.                     if (RSfindvwind(whichWindow)>=0) {
  1186.                         int i;
  1187.  
  1188.                         i=findbyWind( whichWindow);            /* We need to know who */
  1189.                         if (i>=0) {
  1190.                             if ( screens[i].corpse)
  1191.                                 destroyport(i);
  1192.                             else {
  1193.                                 if ( !ReallyClose( i) ) break;
  1194.                                 netclose(screens[i].port);
  1195.                                 destroyport(i);
  1196.                                 }
  1197.                             }
  1198.                         NoWindow();
  1199.                         }
  1200.                     else if (MacRGfindwind( whichWindow) >=0) {
  1201.                         int i;
  1202.                         i= MacRGfindwind( whichWindow);
  1203.                         MacRGdestroy( i);
  1204.                         NoWindow();
  1205.                         }
  1206.                     else {
  1207.                         destroyGraphics( RGgetVG(whichWindow));
  1208.                         NoWindow();
  1209.                         }
  1210.                     }
  1211.                 break;
  1212.             case inDrag:
  1213.                 if ((whichWindow != FrontWindow()) &&
  1214.                         (!(myEvent.modifiers & cmdKey)) &&
  1215.                         (!(myEvent.modifiers & optionKey))) {
  1216.                     SelectWindow(whichWindow);
  1217.                     }
  1218.                 DragWindow(whichWindow, myEvent.where, &dragRect);        /* BYU LSC */
  1219.                 break;
  1220.             case inZoomIn:
  1221.             case inZoomOut:
  1222.                 if (TrackBox( whichWindow, myEvent.where, code))    /* BYU - from Scott@NCSA. */
  1223.                     RSzoom( whichWindow, code, myEvent.modifiers & shiftKey);
  1224.                 break;
  1225.             case inGrow:
  1226.                 RSsize( whichWindow, (long *) &myEvent.where, myEvent.modifiers);
  1227.                 break;
  1228.             case inContent:
  1229.                 if (whichWindow != FrontWindow()) {
  1230.                     SelectWindow(whichWindow);
  1231.                     }
  1232.                 else
  1233.                     if (RSclick( whichWindow, (long *) &myEvent.where,
  1234.                             (myEvent.modifiers & shiftKey),
  1235.                             (myEvent.modifiers & optionKey)) <0) {
  1236.                         SetPort(whichWindow);
  1237.                         GlobalToLocal(&myEvent.where);
  1238.                         RGmousedown(whichWindow, &myEvent.where );
  1239.                         }
  1240.                 break;
  1241.             default:
  1242.                 break;
  1243.             }
  1244.             break;
  1245.  
  1246.         case updateEvt:
  1247.             if (RSupdate((GrafPtr) myEvent.message))
  1248.                 if (MacRGupdate((WindowPtr) myEvent.message))
  1249.                     if (RGupdate((GrafPtr) myEvent.message) ==0) 
  1250.                         TekDisable(RGgetVG((GrafPtr) myEvent.message));
  1251.             break;
  1252.  
  1253.         case keyDown:
  1254.         case autoKey:
  1255.             doKeys();        /* All key events are processed through here */
  1256.             break;
  1257.  
  1258.         case diskEvt:            /* check to see if disk needs to be initialized */
  1259.             myEvent.where.h = 100; myEvent.where.v = 120;
  1260.             if (noErr != (( myEvent.message >> 16 ) & 0xffff )) {    /* check hi word */
  1261.                 DILoad();
  1262.                 DIBadMount( myEvent.where, myEvent.message);    /* BYU LSC */
  1263.                 DIUnload();
  1264.             }
  1265.             break;
  1266.  
  1267.         case activateEvt:
  1268.             if ((myEvent.modifiers & activeFlag)==1) {
  1269.                 int i;
  1270.     
  1271.                 putln("enable event");
  1272.                 AdjustMenus();
  1273.                 DrawMenuBar();
  1274.                 i=findbyWind((GrafPtr) myEvent.message);    /* We need to know who */
  1275.                 if (i>=0) {
  1276.                     if ((screens[i].curgraph>-1) && (!(myEvent.modifiers & optionKey)))
  1277.                         detachGraphics(screens[i].curgraph);
  1278.                     changeport(scrn,i);
  1279.                     scrn=i;
  1280.                     }
  1281.                 if ((i=RSfindvwind((GrafPtr) myEvent.message))>=0) {
  1282.                     if (RSTextSelected(i)) {                    /* BYU 2.4.11 */
  1283.                         EnableItem(myMenus[Fil],FLprint);        /* BYU 2.4.11 */
  1284.                         EnableItem(myMenus[Edit],EDcopy);        /* BYU 2.4.11 */
  1285.                         EnableItem(myMenus[Edit],EDcopyt);        /* BYU 2.4.11 */
  1286.                     } else {                                    /* BYU 2.4.11 */
  1287.                         DisableItem(myMenus[Fil],FLprint);        /* BYU 2.4.11 */
  1288.                         DisableItem(myMenus[Edit],EDcopy);        /* BYU 2.4.11 */
  1289.                         DisableItem(myMenus[Edit],EDcopyt);        /* BYU 2.4.11 */
  1290.                     }                                            /* BYU 2.4.11 */
  1291.                     RSactivate(i);
  1292.                     myfrontwindow=(WindowPeek) myEvent.message;
  1293.                     myfronttype=DEC_WINDOW;
  1294.                     myfrontvs = i;
  1295.                     myfrontRgn =0L;
  1296.                     updateCursor(1);
  1297.                 } else {                    
  1298.                     myfrontwindow=(WindowPeek) myEvent.message;
  1299.                     myfronttype=TEK_WINDOW;
  1300.                     myfrontRgn =0L;
  1301.                     updateCursor(1);
  1302.                     if ( (i = RGgetdnum((GrafPtr) myEvent.message)) >-1) {
  1303.                         if (( i = RGgetVS( i)) >-1) {
  1304.                             EnableItem(myMenus[Fil],FLprint);    /* BYU 2.4.11 - enable printing */
  1305.                             EnableItem(myMenus[Edit],EDcopy);    /* BYU 2.4.11 - enable copying */
  1306.                             DisableItem(myMenus[Edit],EDcopyt);    /* BYU 2.4.11 */
  1307.                             i = findbyVS( i);
  1308.                             changeport(scrn,i);
  1309.                             scrn=i;
  1310.                             }
  1311.                         }
  1312.                 }
  1313.             } else {
  1314.                 int i;
  1315.  
  1316.                 putln("disable event");
  1317.                 AdjustMenus();
  1318.                 DrawMenuBar();
  1319.                 if ((i=RSfindvwind((GrafPtr) myEvent.message))>=0)
  1320.                     RSdeactivate(i);
  1321.                 NoWindow();
  1322.                 }
  1323.             break;
  1324.         case app4Evt:
  1325.             switch(( myEvent.message >>24) &0xff) {        /* App4 is a multi-event event */
  1326.                 case switchEvt:
  1327.                     if (myEvent.message & 0x20)
  1328.                         /*Convert clipboard here if necc. (it is not)*/;
  1329.  
  1330.                     if (myEvent.message & 0x1) {        /* Resume Event */
  1331.                         GrafPtr window;
  1332. /*                        int vs;                            /* BYU 2.4.11 - defined above. */
  1333.  
  1334.                         putln("resume");
  1335.                         suspended = FALSE;                /* We are no longer in suspension */
  1336.                         DisableItem( myMenus[Edit],EDcut);
  1337.                         DisableItem( myMenus[Edit],EDundo);
  1338.                         DisableItem( myMenus[Edit],EDclear);
  1339.  
  1340.                         initKeyBoardMapping();            /* BYU 2.4.12 - keyboard changed? */
  1341.  
  1342.                         if (theWorld.systemVersion < 0x0700)    /* BYU 2.4.18 */
  1343.                             optionKeys();                        /* BYU 2.4.18 */
  1344.  
  1345.                         window = FrontWindow();            /* Who's on first */
  1346.                         if ( (vs=RSfindvwind(window)) >= 0) {
  1347.                             RSactivate(vs);
  1348.                             myfrontwindow = (WindowPeek) window;
  1349.                             myfronttype=DEC_WINDOW;
  1350.                             myfrontvs = vs;
  1351.                             myfrontRgn =0L;
  1352.                             updateCursor(1);
  1353.                         } else if ( (long)window != 0L) {
  1354.                             myEvent.message = (long) window;
  1355.                             myEvent.modifiers |= activeFlag;
  1356.                             myEvent.what = activateEvt;
  1357.                             myEvent.when = TickCount();
  1358.                             SystemEvent( &myEvent);
  1359.                             }
  1360.                         }
  1361.                     else {                                /* Suspend Event */
  1362.                         GrafPtr window;
  1363. /*                        int vs;                            /* BYU 2.4.11 - defined above. */
  1364.  
  1365.                         putln( "suspend");
  1366.                         suspended=TRUE;                    /* We be in waitin' */
  1367.                         EnableItem( myMenus[Edit],EDcut);
  1368.                         EnableItem( myMenus[Edit],EDundo);
  1369.                         EnableItem( myMenus[Edit],EDclear);
  1370.  
  1371.                         if (theWorld.systemVersion < 0x0700)    /* BYU 2.4.18 */
  1372.                             optionKeysOff();                    /* BYU 2.4.18 */
  1373.  
  1374.                         window = FrontWindow();            /* Who's on first */
  1375.                         if ((window = FrontWindow())) {
  1376.                             if ( (vs=RSfindvwind(window)) >= 0)
  1377.                                 RSdeactivate(vs);
  1378.                             else if ( (long)window != 0L) {
  1379.                                 myEvent.message = (long) window;
  1380.                                 myEvent.modifiers &= (~activeFlag);
  1381.                                 myEvent.what = activateEvt;
  1382.                                 myEvent.when = TickCount();
  1383.                                 SystemEvent( &myEvent);
  1384.                                 }
  1385.                             }
  1386.                         NoWindow();
  1387.                         }
  1388.                     break;            /* switch of myEvent.message >>24 */
  1389.                 }
  1390.             break;
  1391.         }
  1392.  
  1393.     } else if (cursorBlink && !suspended) {                /* BYU 2.4.11 */
  1394.         whichWindow = FrontWindow();                    /* BYU 2.4.11 */
  1395.         if ( (vs=RSfindvwind(whichWindow)) >= 0)        /* BYU 2.4.11 */
  1396.             if (vs == screens[scrn].vs)                    /* BYU 2.4.11 */
  1397.                 RScursblink(vs);                        /* BYU 2.4.11 */
  1398.     }                                                    /* BYU 2.4.11 */
  1399.     updateCursor(0);
  1400. }
  1401.  
  1402. void Wait4Mouse
  1403.   (
  1404.     void
  1405.   )
  1406. {
  1407.     EventRecord myEvent;
  1408.  
  1409.     while(!EventAvail(WaitEvents,&myEvent))
  1410.       {
  1411.         DoModem();                                        /* BYU 2.4.15 */
  1412.         Stask();
  1413. #if 0                                                    /* BYU 2.4.15 */
  1414.         DoNetEvents();                                    /* BYU 2.4.15 */
  1415. #endif                                                    /* BYU 2.4.15 */
  1416. #if 0                                                    /* BYU 2.4.15 */
  1417.         rftpd(0);
  1418. #endif                                                    /* BYU 2.4.15 */
  1419.       } /* while */
  1420.     FlushEvents( WaitEvents, 0 );
  1421. }
  1422.  
  1423. void WaitSeconds                                        /* BYU 2.4.15 */
  1424.   (                                                        /* BYU 2.4.15 */
  1425.     int myseconds                                        /* BYU 2.4.15 */
  1426.   )                                                        /* BYU 2.4.15 */
  1427. {                                                        /* BYU 2.4.15 */
  1428.     long mytime = TickCount() + 60 * myseconds;            /* BYU 2.4.15 */
  1429.                                                         /* BYU 2.4.15 */
  1430.     while(mytime > TickCount())                            /* BYU 2.4.15 */
  1431.       {                                                    /* BYU 2.4.15 */
  1432.         DoModem();                                        /* BYU 2.4.15 */
  1433.         Stask();                                        /* BYU 2.4.15 */
  1434.         DoNetEvents();                                    /* BYU 2.4.15 */
  1435.       } /* while */                                        /* BYU 2.4.15 */
  1436.     FlushEvents( WaitEvents, 0 );                        /* BYU 2.4.15 */
  1437. }                                                        /* BYU 2.4.15 */
  1438.  
  1439. int getmacro
  1440.   (
  1441.     int n,
  1442.     unsigned char *dest
  1443.   )
  1444. {
  1445.     unsigned char *s;
  1446.  
  1447.     if (n<0 || n>9)
  1448.         return(-1);
  1449.  
  1450.     s = macro[n];
  1451.     while (*s) {
  1452.         switch( *s) {
  1453.         case MACRO_IP :
  1454.             *dest++='\\';
  1455.             *dest++='i';
  1456.             break;
  1457.         case MACRO_LINES :
  1458.             *dest++='\\';
  1459.             *dest++='#';
  1460.             break;
  1461.         case '\\':
  1462.             *dest++='\\';
  1463.             *dest++='\\';
  1464.             break;
  1465.         case '\015':
  1466.             *dest++='\\';
  1467.             *dest++='r';
  1468.             break;
  1469.         case '\012':
  1470.             *dest++='\\';
  1471.             *dest++='n';
  1472.             break;
  1473.             
  1474. #ifdef OLD_CRAP
  1475.         case '\015':
  1476.             s++;
  1477.             if (*s == '\012' || *s=='\000') {
  1478.                 *dest++='\\';
  1479.                 *dest++='n';
  1480.                 }
  1481.             else {
  1482.                 *dest++='\\';
  1483.                 *dest++='0';
  1484.                 *dest++='1';
  1485.                 *dest++='5';
  1486.                 s--;
  1487.                 }
  1488.             break;
  1489. #endif
  1490.         case '\t':
  1491.             *dest++='\\';
  1492.             *dest++='t';
  1493.             break;
  1494.         default: 
  1495.             if ( isprint(*s)) 
  1496.                 *dest++=*s;
  1497.             else {
  1498.                 *dest++='\\';
  1499.                 *dest++= (*s / 64) +'0';
  1500.                 *dest++= ((*s % 64) / 8)+'0';
  1501.                 *dest++= (*s % 8) +'0';
  1502.                 }
  1503.             break;
  1504.             }
  1505.         s++;
  1506.         }
  1507.     *dest=0;
  1508.     return( 0);
  1509. }
  1510.